package com.menu.service;

import com.menu.dao.BaseDao;
import com.menu.model.BaseModel;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * author: MaHX
 * date: 2019/8/8/19:41
 * description:
 **/
public class BaseService <T extends BaseModel,D extends BaseDao<T>> {
    @Autowired
    private D dao;

    public T findById(String id) {
        return dao.findById(id);
    }

    public T find(T condition) {
        return dao.find(condition);
    }

    public List<T> findList(T condition) {
        return dao.findList(condition);
    }

    public List<T> findAll() {
        return dao.findAll();
    }

   public void save(T t){
        if (t.getId() != null && !"".equals(t.getId())){
            t.preUpdate();
            dao.update(t);
        }else {
            t.preInsert();
            dao.insert(t);
        }
   }

    public void delete(T condition) {
        dao.delete(condition);
    }
}
